#include"compiler.hpp"
#include"runner.hpp"
#include"compile_run.hpp"
#include"../comm/httplib.h"
using namespace ns_compiler;
using namespace ns_runner;
using namespace ns_compile_and_run;
using namespace httplib;

void Usage(const std::string&proc )
{
    std::cout<<proc<<" port"<<std::endl;
}
int main(int argc,char* argv[])
{
    //我们用 ./compile_server port 的方式启动 compile_server 服务，所以有两个命令行参数
    if(argc!=2)
    {
        Usage(argv[0]);
    }
    Server svr;
    svr.Post("/compile_server",[](const Request& req,Response& res){
        //从request的body中获取前端传来的序列化之后的json字符串
        std::string in_json=req.body;
        std::string out_json;
        if(!in_json.empty())
        {
            CompileAndRun::Start(in_json,&out_json);
            res.set_content(out_json,"application/json;charset=utf-8");
        }

    });

    svr.listen("0.0.0.0",atoi(argv[1]));//启动http服务


    return 0;
}